import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 沈明月
 * Date: 2022-11-02
 * Time: 23:08
 */
public class TestTwenty {
//返回的数字之和：写一个递归方法，输入一个非负整数，返回组成它的数字之和
    public static int SUM(int n){
        if(n <= 9){
            return n;
        }return n%10 + SUM(n/10);
    }
    public static void main(String[] args) {
        //输入一个非负整数：
        System.out.println("请输入一个非负整数：");
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        //运用方法：
        int sum = SUM(n);
        System.out.println("组成n的各数字之和是："+sum);
    }
}
